package ycl.base.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ycl.base.entity.Province;
import ycl.base.req.ProvinceReq;
import ycl.base.res.ProvinceRes;
import ycl.base.service.ProvinceService;
import ycl.common.ApiResult;
import ycl.common.base.controller.BaseRegionController;
import ycl.common.models.base.A;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 省份设置 前端控制器
 * </p>
 *
 * @author ycl
 * @since 2022-06-22 20:06:26
 */
@RestController
@RequestMapping("/province")
@Api(tags = "省份")
@ApiSupport(order = 2)
public class ProvinceController
		extends BaseRegionController<Province, ProvinceReq, ProvinceRes> {

	@Resource
	private ProvinceService provinceService;

	@Override
	public ApiResult<Province> getByCode(String code) {
		Province province = provinceService.getByCode(code, Province.class);
		return ApiResult.success(province);
	}

	@Override
	public ApiResult<List<Province>> getByParentCode(String code) {
		List<Province> list = provinceService.getByParentCode(code, Province.class);
		return ApiResult.success(list);
	}

	@Override
	public ApiResult<Page<ProvinceRes>> pageList(Province province) {
		return ApiResult.success(provinceService.pageList(province, ProvinceRes.class));
	}

	@Override
	public <E extends ProvinceReq> ApiResult<A> save(HttpServletRequest request, @Valid E e) {
		provinceService.save(request, e, Province.class);
		return ApiResult.success();
	}

	@Override
	public <E extends ProvinceReq> ApiResult<A> update(HttpServletRequest request, @Valid E e) {
		provinceService.update(request, e, Province.class);
		return ApiResult.success();
	}
}

